package com.qianfeng;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



@WebServlet("/getImg")
public class GetImg extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
			String fileName = req.getParameter("fileName");
			
			FileInputStream fis = new FileInputStream("d:\\imgs\\"+fileName);
			
			OutputStream os = resp.getOutputStream(); //获取到输出流
			
			byte[] bs = new byte[1024];
			int len;
			
			while((len=fis.read(bs))!=-1) {
				os.write(bs, 0, len);
			}
			fis.close();
	}
	
	

}
